<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/laypage.css">
    <script src="js/vue/vue.min.js"></script>
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/laypage/laypage.js" charset="utf-8"></script>
    <script src="js/layer/layer.js" charset="utf-8"></script>
</head>

<body>
<div id="app" class="container">

    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="title">新闻标题</label>
            <input type="text" class="form-control" id="title" placeholder="新闻标题">
        </div>
        <button type="button" id="findNews" class="btn btn-success">查询新闻</button>
        <button type="button" id="addNewsBtn" class="btn btn-danger">增加新闻</button>
    </form>


    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>标题</td>
                <td>时间</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{index+1}}</td>
                <td>{{item.title}}</td>
                <td>{{item.contact}}</td>
                <td><a href="#" @click="editEvent(item.id)">编辑</a>|<a href="#" @click="delEvent(item.id)">删除</a> </td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });

    var getNewsPageList = function (curr) {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/getcond',
            data: {
                pageSize: 3,
                pageNum: curr || 1,
                title: $("#title").val()
            },
            success: function (msg) {
                app.result = msg.result;
                //layer分页
                laypage({
                    cont: 'pagenav', //容器，存放分页
                    pages: msg.totalPages,   //总页数
                    skin: '#7D26CD',
                    first: true,
                    last: true,
                    curr: curr || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            getNewsPageList(obj.curr);
                        }
                    }
                });
            }
        });
    }

    getNewsPageList();

        $("#findNews").on("click",function(){
            getNewsPageList();
        });

        $("#addNewsBtn").click(function () {
            layer.open({
                type: 2,
                title: '添加新闻',
                fix: false,
                maxmin: true,
                shadeClose: true,
                area: ['1100px', '600px'],
                content: 'news_add.html',
                end: function () {
                    getNewsPageList();
                }

            });
        });
    var delEvent = function (id) {
         layer.confirm('确认删除吗?', {
             btn: ['残忍删除', '我再想想']
         },function () {
             $.ajax({
                 type:'POST',
                 url:'del',
                 dataType:'json',
                 data:{
                     id:id
                 },
                 success:function () {
                     getNewsPageList();
                     layer.msg("已经删除",{icon:5});
                 }
             });
         } ,
         function () {

         }
         );
    }
    var editEvent = function (id) {
          layer.open({
              type:2,
              title:'编辑新闻',
              fix:false,
              maxmin:true,
              shadeClose:true,
              area:['1100px','600px'],
              content:'/getNews?id='+id,
              end:function () {
                  getNewsPageList();
              }
          });
    }




</script>

</body>
</html>